import { defineStore } from "pinia";

/* defineStore第一个参数为这个状态库的名称 */
export const useUserCounterStore = defineStore('oneselfInfo', {
    /* 创建state */
    state: () => ({
        info: {}
    }),
    /* 计算参数缓存数据 */
    getters: {

    },
    /* 同步异步的方法都写到这里 */
    actions: {
        getInfo() {
            return this.info
        },
        login(one) {
            console.log(one)
            console.log(this.info)
            this.info = one
        },
        logout(){
            this.info = {}
            localStorage.removeItem("my_info")
            localStorage.removeItem("my_cart")
        }
    },
    //   开启缓存 默认存session
    persist: {
        enabled: true,
        // 存localstorage
        strategies: [{
            key: 'my_info',
            storage: localStorage
        }]
    }

})